﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FPC.Offer.Model;
using NLog;
using System.Web.SessionState;
namespace FPC.Offer.UI.GeneralProcessor.Message
{
    /// <summary>
    /// DeleteMessage 的摘要说明
    /// </summary>
    public class DeleteMessage : IHttpHandler, IReadOnlySessionState
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        public void ProcessRequest(HttpContext context)
        {
            FPC.Offer.Service.Message_ReceiveMessageService ReceiveMessage = new Service.Message_ReceiveMessageService();
            FPC.Offer.Service.Message_AddMessageService SendMessage = new Service.Message_AddMessageService();
            context.Response.ContentType = "text/plain";         
            var Actioon = context.Request["Actioon"].ToString();//枚举判断进入哪个方法
            var UserName = context.Session[FPC.Offer.Common.SystemKeys.COOKIE_USER_NAME_REMEMBER];
            var AmilyID = Convert.ToInt32(context.Session[FPC.Offer.Common.SystemKeys.COOKIE_USER_UserID_REMEMBER]);
          
            //收信息批删
            if (Actioon == "dels")
            {
                
                string ReceiveID = context.Request["id"];
                ReceiveID = ReceiveID.Substring(0, ReceiveID.Length - 1);
                if (SendMessage.ame_deletes(ReceiveID) > 0)
                {
                    string cc = "";
                    cc = "操作人警号:" + AmilyID.ToString();
                    cc += ",操作人：" + UserName.ToString() + "删除消息记录";
                    logger.Trace(cc);
                    context.Response.Write(1);
                }
                else
                {
                    context.Response.Write(0);
                }
            }
            //收信息单删
            if(Actioon == "del")
            {
                string id = context.Request["id"];
                Message_ReceiveMessage li = ReceiveMessage.Select().Where(m => m.ReceiveID == Guid.Parse(id)).First();
                li.MessageState = "已删除";
                if(ReceiveMessage.Update(li)>0)
                {
                    string cc = "";
                    cc = "操作人警号:" + AmilyID.ToString();
                    cc += ",操作人：" + UserName.ToString() + "删除消息记录";
                    logger.Trace(cc);
                    context.Response.Write(1);
                }
                else
                {
                    context.Response.Write(0);
                }
            }
            //
            if(Actioon == "adel")
            {
                string id = context.Request["id"];
                Message_SendMessage li = SendMessage.Select().Where(m => m.MessageId ==Guid.Parse(id)).First();
                li.SendState = "已删除";
                if (SendMessage.Update(li) > 0)
                {
                    string cc = "";
                    cc = "操作人警号:" + AmilyID.ToString();
                    cc += ",操作人：" + UserName.ToString() + "删除消息记录";
                    logger.Trace(cc);
                    context.Response.Write(1);
                }
                else
                {
                    context.Response.Write(0);
                }
            }
           

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}